﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Configuration;
using ModuleDALCore;
namespace DAL
{
    public class DALBase
    {
        public DALBase()
        { }
        public void OpenConnect()
        {
            //dung sql server local
            string _Server = ConfigurationSettings.AppSettings["server"].ToString();
            string _Db = ConfigurationSettings.AppSettings["dbname"].ToString();
            string _user = ConfigurationSettings.AppSettings["username"].ToString();
            string _pass = ConfigurationSettings.AppSettings["password"].ToString();
            DBManager.Initialize(ProviderType.SqlServer, CreateConnectionString(_Server, _Db, _user, _pass));
            //neu dung sql sever sommee 
          //  String ChuoiKetNoiSQLSERVERSOMEE ="workstation id=QLKHACHSAN.mssql.somee.com;packet size=4096;user id=thanhthuytest;pwd=thanhthuy;data source=QLKHACHSAN.mssql.somee.com;persist security info=False;initial catalog=QLKHACHSAN";
           // DBManager.Initialize(ProviderType.SqlServer, ChuoiKetNoiSQLSERVERSOMEE);
        }
        private string CreateConnectionString(string Server, string Database, string User, string Pass)
        {
            if (String.IsNullOrEmpty(User) && String.IsNullOrEmpty(Pass))
                return "Server=" + Server + ";" + "Database=" + Database + ";" + "Integrated Security=SSPI";
            else
                return "Server=" + Server + ";" + "Initial Catalog=" + Database + ";" + "Persist Security Info=True;" + "User ID=" + User + ";" + "Password=" + Pass;
               
        }
    }
}
